﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<ThietBiSo.LinQDB.SanPham>" %>

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%@ Import Namespace="ThietBiSo.LinQDB" %>
<%@ Import Namespace="ThietBiSo.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Website - bảng điều khiển
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%
       
        SanPham sp = (SanPham)ViewData["sanphams"];
       
       // int dm = int.Parse(Request.QueryString["cbNhom"]);
        MDanhMuc mdm = new MDanhMuc();
        var vdm = mdm.FindAll();
      
    %>
    <script type="text/javascript">
      

        function submitForm() {
            if (checkForm()) {
                document.forms[0].submit();
            }
        }
        function checkForm() {
            var flag = true;
            var F = document.forms[0];
            var TenSP = document.getElementById("TenSP").value;
           
            var HinhAnh = document.getElementById("HinhAnh").value;
         

            if (TenSP == null || TenSP == "") {
                alert("Chưa nhập tên sản phẩm");
                F.TenSP.focus();
                flag = false;

            }
            else if (HinhAnh == null || HinhAnh == "") {
                alert("Chưa chọn hình ảnh");
                F.HinhAnh.focus();
                flag = false;

            }
           
            return flag;
        }
       

    </script>
    <% using (Html.BeginForm("Edit", "SanPham", FormMethod.Post, new { @enctype = "multipart/form-data" }))
       { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend class="">Sửa sản phẩm</legend>
        <table width="100%">
            <tr>
                <td class="">
                  
                    <input type="button" value="Luu" class="btn" onclick="submitForm();" />
                  
                </td>
                <td class="">
                    <%: Html.ActionLink("Quay lại", "", new { cbNhom = ViewData["urlcbNhom"] })%>
                </td>
            </tr>
            <tr>
                <td class="tableLabel">
                    Danh mục
                </td>
                <td style="color: Red; font-weight: bold;">
                    <%:Html.Hidden("cbNhom",ViewData["urlcbNhom"])%>                   
                    <%: Html.DropDownList("ddlDanhMuc", new SelectList(vdm, "MaDanhMuc", "TenDanhMuc", sp.MaDM), "Chọn danh mục", new { @style = "width:606px;" })%>
                </td>
            </tr>
           
            <tr>
                <td class="tableLabel">
                    Tên Sản phẩm
                </td>
                <td class="tableField">
                    <%:Html.TextBox("TenSP",sp.TenSP, new { @style="width:600px" })%>
                </td>
            </tr>
            <tr>
                <td class="">
                    Hình đại diện
                </td>
                <td class="">
                    <%: Html.Hidden("HiddenHinhAnh", sp.HinhAnh)%>
                    <table width="100%">
                        <tr>
                            <td style="width: 50%">
                                <%:Html.TextBox("HinhAnh", sp.HinhAnh)%>
                                <input type="button" value="Chọn ..." id="btnSelectImg" name="btnSelectImg" />
                                <script type="text/javascript">
                                    $(document).ready(function () {
                                        $("#btnSelectImg").click(function () {
                                            var finder = new CKFinder();
                                            finder.selectActionFunction = function (fileUrl) {
                                                $('#HinhAnh').val(fileUrl);
                                            };
                                            finder.popup();
                                        });
                                    });
                                </script>
                            </td>
                            <td>
                                <%if (sp.HinhAnh == "" || sp.HinhAnh == null || sp.HinhAnh == "noImage")
                                  {%>
                                <img src="<%:Url.Content("~/Content/imagesAdmin/images/nophoto.gif")%>" alt="" width="150px;"
                                    height="150px;" />
                                <%}
                                  else
                                  { %>
                                <img src="<%: sp.HinhAnh%>" alt="" width="150px" height="150px" />
                                <%} %>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
         
            <tr>
                <td class="tableLabel">
                    Thứ tự
                </td>
                <td class="tableField">
                    <%:Html.TextBox("ThuTu", sp.ThuTu)%>
                </td>
            </tr>
           
            <tr>
                <td height="20px">
                </td>
            </tr>
          
        </table>
        <div>
            <script src="<%= Url.Content("~/ckeditor/ckeditor.js") %>" type="text/javascript"></script>
            <script src="<%= Url.Content("~/ckfinder/ckfinder.js")%>" type="text/javascript"></script>
            <%= Html.TextArea("ChiTiet", System.Net.WebUtility.HtmlDecode(sp.ChiTiet))%>
            <script type="text/javascript">

                CKEDITOR.replace('ChiTiet',
             {
                 htmlEncodeOutput: true,
                 enterMode: CKEDITOR.ENTER_BR,
                 filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?type=Images',
                 filebrowserImageUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'
             });
          
            </script>
        </div>
    </fieldset>
    <% } %>
</asp:Content>
